package com.university.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.university.infrastructure.Result;
import com.university.pojo.cqe.command.CmdMovieOrder;
import com.university.pojo.cqe.command.CmdMovieReview;
import com.university.pojo.cqe.query.MovieQuery;
import com.university.pojo.dto.MovieOrderAdminDTO;
import com.university.pojo.dto.MovieOrderUserDTO;
import com.university.service.MovieOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Date: 2021/5/15 18:03
 * @Description:
 */
@Api(tags = {"电影订单接口"})
@RestController
public class MovieOrderController extends BaseController {

    @Resource
    private MovieOrderService movieOrderService;

    @ApiOperation("用户订票")
    @PostMapping("/user/saveMovieOrder")
    public Result saveMovieOrder(@RequestBody CmdMovieOrder cmdMovieOrder) {
        movieOrderService.saveMovieOrder(cmdMovieOrder);
        return ok();
    }

    @ApiImplicitParam(name = "username", value = "用户名", required = true, dataTypeClass = String.class)
    @ApiOperation("用户查询订单")
    @GetMapping("/user/getMovieOrder")
    public Result getMovieOrder(String username) {
        MovieQuery query = new MovieQuery();
        query.setUsername(username);
        List<MovieOrderUserDTO> orderList = movieOrderService.userGetMovieOrder(query);
        return ok(orderList);
    }

    @ApiOperation("管理员查询订单")
    @GetMapping("/admin/getMovieOrder")
    public Result getMovieOrder(String username,
                                @RequestParam(defaultValue = "1") Long page,
                                @RequestParam(defaultValue = "10") Long pageSize) {
        MovieQuery query = new MovieQuery();
        query.setUsername(username);
        query.setPage(page);
        query.setPageSize(pageSize);
        IPage<MovieOrderAdminDTO> orderList = movieOrderService.adminGetMovieOrder(query);
        return ok(orderList);
    }

    @ApiOperation("用户评价")
    @PostMapping("/user/review")
    public Result review(@RequestBody CmdMovieReview cmdMovieReview) {
        movieOrderService.review(cmdMovieReview);
        return ok();
    }


}
